<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-json-lib.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<%
Response.ContentType = "application/json"
action=request("action")
contactid=request("contactid")

companyid=request("companyid")
name=request("name")
telephone=request("telephone")
sex=request("sex")
age=request("age")
if age="" then age=0
qq=request("qq")
msn=request("msn")
email=request("email")
contact_memo=request("contact_memo")
contact_update=formattime(now(),"{Y}-{m}-{d} {h}:{n}:{s}")

if action="set" then
	if contactid="" then
		sqlset="replace into crm_contact(id,company,name,telephone,sex,age,qq,msn,email,contact_update,memo,empe) values(Null,'"&companyid&"','"&name&"','"&telephone&"',"&sex&","&age&",'"&qq&"','"&msn&"','"&email&"','"&contact_update&"','"&contact_memo&"',"&session("iId")&")"
		' response.write(sql)
		sqlget="SELECT crm_contact.*,crm_empe.empe as empename FROM crm_contact,crm_empe where crm_empe.id=crm_contact.empe and crm_contact.id=last_insert_rowid()"
	else 
		sqlset="replace into crm_contact(id,company,name,telephone,sex,age,qq,msn,email,contact_update,memo,empe) values('"&contactid&"','"&companyid&"','"&name&"','"&telephone&"',"&sex&","&age&",'"&qq&"','"&msn&"','"&email&"','"&contact_update&"','"&contact_memo&"',"&session("iId")&")"
	' response.write(sql)
		sqlget="SELECT crm_contact.*,crm_empe.empe as empename FROM crm_contact,crm_empe where crm_empe.id=crm_contact.empe and crm_contact.id="&contactid
	end if
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection = conn
	cmd.CommandText = sqlset
	cmd.Execute
	set cmd=nothing
	
end if
if action="get" and contactid<>"" then
	sqlget="SELECT crm_contact.*,crm_empe.empe as empename FROM crm_contact,crm_empe where crm_empe.id=crm_contact.empe and crm_contact.id="&contactid
end if

Set json = jsObject()

Set rs = conn.Execute(sqlget)
if not rs.eof and not rs.bof then
	set json("rData")=jsObject
	json("rData")("id")=rs("id")
	json("rData")("company")=rs("company")
	json("rData")("name")=rs("name")
	json("rData")("telephone")=rs("telephone")
	json("rData")("sex")=rs("sex")
	json("rData")("age")=rs("age")
	json("rData")("qq")=rs("qq")
	json("rData")("msn")=rs("msn")
	json("rData")("email")=rs("email")
	json("rData")("contact_update")=rs("contact_update")
	json("rData")("memo")=rs("memo")
	json("rData")("empe")=rs("empe")
	json("rData")("empename")=rs("empename")
end if
json("bStatus")=true
json.Flush


%>  

<!--#include file="lib/connclose.asp"-->